package com.guan.eduservice.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.guan.commonutils.R;
import com.guan.eduservice.client.VodClient;
import com.guan.eduservice.entity.EduVideo;
import com.guan.eduservice.service.EduVideoService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 课程视频（课程小节） 前端控制器
 * </p>
 *
 * @author testjava
 * @since 2023-01-01
 */
@RestController
@RequestMapping("/eduservice/video/*")
@CrossOrigin
public class EduVideoController {

    @Autowired
    private EduVideoService videoService;

    @Autowired
    private VodClient vodClient;
    /**
     * 添加小节
     * @param eduVideo
     * @return
     */
    @PostMapping("addVideo")
    public R addVideo(@RequestBody EduVideo eduVideo){
        videoService.save(eduVideo);
        return R.ok();
    }

    /**
     * 删除小节
     * @param id
     * @return
     */
    @DeleteMapping("{id}")
    public R deleteVideo(@PathVariable String id){
        //根据小节id获取视频id
        EduVideo eduVideo = videoService.getById(id);
        String videoId = eduVideo.getVideoSourceId();
        if (StringUtils.isNotBlank(videoId)){
            //根据视频id远程调用
            vodClient.removeAliyunVideo(videoId);
        }
        videoService.removeById(id);
        return R.ok();
    }

    /**
     * TODO 修改小节
     */
}

